Produced by Araxis Merge on 2023-03-13 03:00:43 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Porto v4.0.4/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/ResourceModel/Fulltext | Collection.php | 2022-04-22 07:34:10 +0000 |
| 2 | Porto v4.0.5/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/ResourceModel/Fulltext | Collection.php | 2022-12-08 01:34:28 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 132 | 824 |
| Changed | 101 | 633 |
| Inserted | 14 | 108 |
| Removed | 16 | 47 |
| Whitespace | Consecutive whitespace is treated as a single space |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
| Active line-pairing rules |
No regular expressions were active.
| 1 | <?php | 1 | <?php | |||
| 2 | /** | 2 | /** | |||
| 3 | * Mageplaza | 3 | * Mageplaza | |||
| 4 | * | 4 | * | |||
| 5 | * NOTICE OF LICENSE | 5 | * NOTICE OF LICENSE | |||
| 6 | * | 6 | * | |||
| 7 | * This source file is subject to the Mageplaza.com license that is | 7 | * This source file is subject to the Mageplaza.com license that is | |||
| 8 | * available through the world-wide-web at this URL: | 8 | * available through the world-wide-web at this URL: | |||
| 9 | * https://www.mageplaza.com/LICENSE.txt | 9 | * https://www.mageplaza.com/LICENSE.txt | |||
| 10 | * | 10 | * | |||
| 11 | * DISCLAIMER | 11 | * DISCLAIMER | |||
| 12 | * | 12 | * | |||
| 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | |||
| 14 | * version in the future. | 14 | * version in the future. | |||
| 15 | * | 15 | * | |||
| 16 | * @category Mageplaza | 16 | * @category Mageplaza | |||
| 17 | * @package Mageplaza_LayeredNavigation | 17 | * @package Mageplaza_LayeredNavigation | |||
| 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | |||
| 19 | * @license https://www.mageplaza.com/LICENSE.txt | 19 | * @license https://www.mageplaza.com/LICENSE.txt | |||
| 20 | */ | 20 | */ | |||
| 21 | 21 | |||||
| 22 | namespace Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext; | 22 | namespace Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext; | |||
| 23 | 23 | |||||
| 24 | use Exception; | 24 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\DefaultFilterStrategyApplyChecker; | |||
| 25 | use Magento\Catalog\Model\Category; | 25 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\DefaultFilterStrategyApplyCheckerInterface; | |||
| 26 | use Magento\Catalog\Model\Indexer\Product\Flat\State; | 26 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverInterface; | |||
| 27 | use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory; | 27 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverFactory; | |||
| 28 | use Magento\Catalog\Model\Product\OptionFactory; | 28 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolverInterface; | |||
| 29 | use Magento\Catalog\Model\ResourceModel\Helper; | 29 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolverFactory; | |||
| 30 | use Magento\Catalog\Model\ResourceModel\Url; | 30 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierFactory; | |||
| 31 | use Magento\CatalogSearch\Model\Search\RequestGenerator; | 31 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface; | |||
| 32 | use Magento\Config\Model\Config\Backend\Admin\Custom; | |||||
| 33 | use Magento\Customer\Api\GroupManagementInterface; | |||||
| 34 | use Magento\Customer\Model\Session; | |||||
| 35 | use Magento\Eav\Model\Config; | |||||
| 36 | use Magento\Eav\Model\EntityFactory as EavEntityFactory; | |||||
| 37 | use Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverFactory; | |||||
| 38 | use Magento\Framework\Api\FilterBuilder; | |||||
| 39 | use Magento\Framework\Api\Search\SearchResultFactory; | |||||
| 40 | use Magento\Framework\Api\Search\SearchResultInterface; | |||||
| 41 | use Magento\Framework\App\Config\ScopeConfigInterface; | |||||
| 42 | use Magento\Framework\App\ObjectManager; | |||||
| 43 | use Magento\Framework\App\Request\Http; | |||||
| 44 | use Magento\Framework\App\ResourceConnection; | |||||
| 45 | use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; | |||||
| 46 | use Magento\Framework\Data\Collection\EntityFactory; | |||||
| 47 | use Magento\Framework\DB\Adapter\AdapterInterface; | |||||
| 48 | use Magento\Framework\DB\Select; | 32 | use Magento\Framework\DB\Select; | |||
| 49 | use Magento\Framework\Event\ManagerInterface; | 33 | use Magento\Framework\Api\Search\SearchResultInterface; | |||
| 50 | use Magento\Framework\Exception\LocalizedException; | 34 | use Magento\CatalogSearch\Model\Search\RequestGenerator; | |||
| 35 | use Magento\Framework\EntityManager\MetadataPool; | |||||
| 51 | use Magento\Framework\Exception\StateException; | 36 | use Magento\Framework\Exception\StateException; | |||
| 52 | use Magento\Framework\Module\Manager; | |||||
| 53 | use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage; | |||||
| 54 | use Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory; | |||||
| 55 | use Magento\Framework\Search\Request\EmptyRequestDataException; | 37 | use Magento\Framework\Search\Request\EmptyRequestDataException; | |||
| 56 | use Magento\Framework\Stdlib\DateTime; | 38 | use Magento\Framework\Search\Request\NonExistingRequestNameException; | |||
| 57 | use Magento\Framework\Stdlib\DateTime\TimezoneInterface; | 39 | use Magento\Framework\Api\Search\SearchResultFactory; | |||
| 58 | use Magento\Framework\Validator\UniversalFactory; | 40 | use Magento\Framework\Exception\LocalizedException; | |||
| 59 | use Magento\Search\Api\SearchInterface; | 41 | use Magento\Framework\App\ObjectManager; | |||
| 60 | use Magento\Store\Model\ScopeInterface; | 42 | use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory; | |||
| 61 | use Magento\Store\Model\Store; | 43 | use Magento\Store\Model\Store; | |||
| 62 | use Magento\Store\Model\StoreManagerInterface; | |||||
| 63 | use Mageplaza\LayeredNavigation\Model\Search\SearchCriteriaBuilder; | |||||
| 64 | use Psr\Log\LoggerInterface; | |||||
| 65 | use RuntimeException; | |||||
| 66 | use Zend_Db_Exception; | |||||
| 67 | use Zend_Db_Expr; | |||||
| 68 | 44 | |||||
| 69 | /** | 45 | /** | |||
| 70 | * Class Collection | 46 | * Fulltext Collection | |||
| 71 | * @package Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext | 47 | * | |||
| 48 | * This collection should be refactored to not have dependencies on MySQL-specific implementation. | |||||
| 49 | * | |||||
| 50 | * @api | |||||
| 51 | * @since 100.0.2 | |||||
| 52 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects) | |||||
| 53 | * @SuppressWarnings(PHPMD.TooManyFields) | |||||
| 54 | * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) | |||||
| 72 | */ | 55 | */ | |||
| 73 | class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection | 56 | class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection | |||
| 74 | { | 57 | { | |||
| 75 | /** @var Collection|null Clone collection */ | 58 | /** | |||
| 76 | public $collectionClone = null; | 59 | * @var string | |||
| 77 | 60 | */ | ||||
| 78 | /** @var string */ | |||||
| 79 | private $queryText; | 61 | private $queryText; | |||
| 80 | 62 | |||||
| 81 | /** @var string|null */ | 63 | /** | |||
| 82 | private $order = null; | 64 | * @var string | |||
| 83 | 65 | */ | ||||
| 84 | /** @var string */ | |||||
| 85 | private $searchRequestName; | 66 | private $searchRequestName; | |||
| 86 | 67 | |||||
| 87 | /** @var TemporaryStorageFactory */ | 68 | /** | |||
| 88 | private $temporaryStorageFactory; | 69 | * @var \Magento\Search\Api\SearchInterface | |||
| 89 | 70 | */ | ||||
| 90 | /** @var SearchInterface */ | |||||
| 91 | private $search; | 71 | private $search; | |||
| 92 | 72 | |||||
| 93 | /** @var | 73 | /** | |||
| 74 | | |||||
| 75 | */ | |||||
| 94 | private $searchCriteriaBuilder; | 76 | private $searchCriteriaBuilder; | |||
| 95 | 77 | |||||
| 96 | /** @var | 78 | /** | |||
| 79 | | |||||
| 80 | */ | |||||
| 97 | private $searchResult; | 81 | private $searchResult; | |||
| 98 | 82 | |||||
| 99 | /** @var FilterBuilder */ | 83 | /** | |||
| 100 | private $filterBuilder; | 84 | * @var SearchResultFactory | |||
| 85 | */ | |||||
| 86 | private $searchResultFactory; | |||||
| 101 | 87 | |||||
| 102 | /** | 88 | /** | |||
| 103 | * @var Http | 89 | * @var \Magento\Framework\Api\FilterBuilder | |||
| 104 | */ | 90 | */ | |||
| 105 | protected $request; | 91 | private $filterBuilder; | |||
| 106 | 92 | |||||
| 107 | /** | 93 | /** | |||
| 108 | * @var array | 94 | * @var SearchCriteriaResolverFactory | |||
| 109 | */ | 95 | */ | |||
| 110 | private $searchOrders; | 96 | private $searchCriteriaResolverFactory; | |||
| 97 | ||||||
| 111 | /** | 98 | /** | |||
| 112 | * @var SearchResultFactory | 99 | * @var SearchResultApplierFactory | |||
| 113 | */ | 100 | */ | |||
| 114 | protected $searchResultFactory; | 101 | private $searchResultApplierFactory; | |||
| 102 | ||||||
| 115 | /** | 103 | /** | |||
| 116 | * @var TotalRecordsResolverFactory | 104 | * @var TotalRecordsResolverFactory | |||
| 117 | */ | 105 | */ | |||
| 118 | protected $totalRecordsResolverFactory; | 106 | private $totalRecordsResolverFactory; | |||
| 119 | 107 | |||||
| 120 | /** | 108 | /** | |||
| 121 | * Collection constructor. | 109 | * @var array | |||
| 122 | | 110 | */ | |||
| 123 | * @param | 111 | private $searchOrders; | |||
| 124 | * @param | 112 | ||||
| 125 | * @param | 113 | /** | |||
| 126 | * @param | 114 | * @var DefaultFilterStrategyApplyCheckerInterface | |||
| 127 | * @param | 115 | */ | |||
| 128 | * @param | 116 | private $defaultFilterStrategyApplyChecker; | |||
| 129 | * @param EavEntityFactory $eavEntityFactory | 117 | ||||
| 130 | * @param | 118 | /** @var Collection|null Clone collection */ | |||
| 131 | * @param | 119 | public $collectionClone = null; | |||
| 132 | * @param | 120 | ||||
| 133 | * @param | 121 | /** @var bool If this variable is True, the search result will not separate item by page */ | |||
| 134 | * @param State $productFlatState | 122 | protected $_getAllData = false; | |||
| 135 | * @param | 123 | ||||
| 136 | * @param | 124 | /** | |||
| 137 | * @param | 125 | * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory | |||
| 138 | * @param | 126 | * @param \Psr\Log\LoggerInterface $logger | |||
| 139 | * @param | 127 | * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy | |||
| 140 | * @param | 128 | * @param \Magento\Framework\Event\ManagerInterface $eventManager | |||
| 141 | * @param | 129 | * @param \Magento\Eav\Model\Config $eavConfig | |||
| 142 | * @param TemporaryStorageFactory $tempStorageFactory | 130 | * @param \Magento\Framework\App\ResourceConnection $resource | |||
| 143 | * @param Http $request | 131 | * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory | |||
| 144 | * @param TotalRecordsResolverFactory $totalRecordsResolver | 132 | * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper | |||
| 145 | * @param | 133 | * @param \Magento\Framework\Validator\UniversalFactory $universalFactory | |||
| 134 | * @param \Magento\Store\Model\StoreManagerInterface $storeManager | |||||
| 135 | * @param \Magento\Framework\Module\Manager $moduleManager | |||||
| 136 | * @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState | |||||
| 137 | * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | |||||
| 138 | * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory | |||||
| 139 | * @param \Magento\Catalog\Model\ResourceModel\Url $catalogUrl | |||||
| 140 | * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate | |||||
| 141 | * @param \Magento\Customer\Model\Session $customerSession | |||||
| 142 | * @param \Magento\Framework\Stdlib\DateTime $dateTime | |||||
| 143 | * @param \Magento\Customer\Api\GroupManagementInterface $groupManagement | |||||
| 144 | * @param mixed $catalogSearchData | |||||
| 145 | * @param mixed $requestBuilder | |||||
| 146 | * @param mixed $searchEngine | |||||
| 147 | * @param mixed $temporaryStorageFactory | |||||
| 148 | * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection | |||||
| 146 | * @param string $searchRequestName | 149 | * @param string $searchRequestName | |||
| 147 | * @param SearchResultFactory|null $searchResultFactory | 150 | * @param SearchResultFactory|null $searchResultFactory | |||
| 151 | * @param ProductLimitationFactory|null $productLimitationFactory | |||||
| 152 | * @param MetadataPool|null $metadataPool | |||||
| 153 | * @param \Magento\Search\Api\SearchInterface|null $search | |||||
| 154 | * @param \Magento\Framework\Api\Search\SearchCriteriaBuilder|null $searchCriteriaBuilder | |||||
| 155 | * @param \Magento\Framework\Api\FilterBuilder|null $filterBuilder | |||||
| 156 | * @param SearchCriteriaResolverFactory|null $searchCriteriaResolverFactory | |||||
| 157 | * @param SearchResultApplierFactory|null $searchResultApplierFactory | |||||
| 158 | * @param TotalRecordsResolverFactory|null $totalRecordsResolverFactory | |||||
| 159 | * @param DefaultFilterStrategyApplyCheckerInterface|null $defaultFilterStrategyApplyChecker | |||||
| 160 | * @SuppressWarnings(PHPMD.ExcessiveParameterList) | |||||
| 161 | * @SuppressWarnings(PHPMD.NPathComplexity) | |||||
| 162 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) | |||||
| 148 | */ | 163 | */ | |||
| 149 | public function __construct( | 164 | public function __construct( | |||
| 150 | | 165 | \Magento\Framework\Data\Collection\EntityFactory $entityFactory, | |||
| 151 | | 166 | \Psr\Log\LoggerInterface $logger, | |||
| 152 | | 167 | \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, | |||
| 153 | | 168 | \Magento\Framework\Event\ManagerInterface $eventManager, | |||
| 154 | | 169 | \Magento\Eav\Model\Config $eavConfig, | |||
| 155 | | 170 | \Magento\Framework\App\ResourceConnection $resource, | |||
| 156 | EavEntityFactory $eavEntityFactory, | 171 | \Magento\Eav\Model\EntityFactory $eavEntityFactory, | |||
| 157 | | 172 | \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, | |||
| 158 | | 173 | \Magento\Framework\Validator\UniversalFactory $universalFactory, | |||
| 159 | | 174 | \Magento\Store\Model\StoreManagerInterface $storeManager, | |||
| 160 | | 175 | \Magento\Framework\Module\Manager $moduleManager, | |||
| 161 | State $productFlatState, | 176 | \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState, | |||
| 162 | | 177 | \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | |||
| 163 | | 178 | \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, | |||
| 164 | Url $catalogUrl, | 179 | \Magento\Catalog\Model\ResourceModel\Url $catalogUrl, | |||
| 165 | | 180 | \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, | |||
| 166 | | 181 | \Magento\Customer\Model\Session $customerSession, | |||
| 167 | | 182 | \Magento\Framework\Stdlib\DateTime $dateTime, | |||
| 168 | | 183 | \Magento\Customer\Api\GroupManagementInterface $groupManagement, | |||
| 169 | TemporaryStorageFactory $tempStorageFactory, | 184 | $catalogSearchData = null, | |||
| 170 | Http $request, | 185 | $requestBuilder = null, | |||
| 171 | TotalRecordsResolverFactory $totalRecordsResolver, | 186 | $searchEngine = null, | |||
| 172 | | 187 | $temporaryStorageFactory = null, | |||
| 188 | \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, | |||||
| 173 | $searchRequestName = 'catalog_view_container', | 189 | $searchRequestName = 'catalog_view_container', | |||
| 174 | SearchResultFactory $searchResultFactory = null | 190 | SearchResultFactory $searchResultFactory = null, | |||
| 191 | ProductLimitationFactory $productLimitationFactory = null, | |||||
| 192 | MetadataPool $metadataPool = null, | |||||
| 193 | \Magento\Search\Api\SearchInterface $search = null, | |||||
| 194 | \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder = null, | |||||
| 195 | \Magento\Framework\Api\FilterBuilder $filterBuilder = null, | |||||
| 196 | SearchCriteriaResolverFactory $searchCriteriaResolverFactory = null, | |||||
| 197 | SearchResultApplierFactory $searchResultApplierFactory = null, | |||||
| 198 | TotalRecordsResolverFactory $totalRecordsResolverFactory = null, | |||||
| 199 | DefaultFilterStrategyApplyCheckerInterface $defaultFilterStrategyApplyChecker = null | |||||
| 175 | ) { | 200 | ) { | |||
| 201 | $this->searchResultFactory = $searchResultFactory ?? \Magento\Framework\App\ObjectManager::getInstance() | |||||
| 202 | ->get(\Magento\Framework\Api\Search\SearchResultFactory::class); | |||||
| 176 | parent::__construct( | 203 | parent::__construct( | |||
| 177 | $entityFactory, | 204 | $entityFactory, | |||
| 178 | $logger, | 205 | $logger, | |||
| 179 | $fetchStrategy, | 206 | $fetchStrategy, | |||
| 180 | $eventManager, | 207 | $eventManager, | |||
| 181 | $eavConfig, | 208 | $eavConfig, | |||
| 182 | $resource, | 209 | $resource, | |||
| 183 | $eavEntityFactory, | 210 | $eavEntityFactory, | |||
| 184 | $resourceHelper, | 211 | $resourceHelper, | |||
| 185 | $universalFactory, | 212 | $universalFactory, | |||
| 186 | $storeManager, | 213 | $storeManager, | |||
| 187 | $moduleManager, | 214 | $moduleManager, | |||
| 188 | $productFlatState, | 215 | $catalogProductFlatState, | |||
| 189 | $scopeConfig, | 216 | $scopeConfig, | |||
| 190 | $productOptionFactory, | 217 | $productOptionFactory, | |||
| 191 | $catalogUrl, | 218 | $catalogUrl, | |||
| 192 | $localeDate, | 219 | $localeDate, | |||
| 193 | $customerSession, | 220 | $customerSession, | |||
| 194 | $dateTime, | 221 | $dateTime, | |||
| 195 | $groupManagement, | 222 | $groupManagement, | |||
| 196 | $connection | 223 | $connection, | |||
| 224 | $productLimitationFactory, | |||||
| 225 | $metadataPool | |||||
| 197 | ); | 226 | ); | |||
| 198 | ||||||
| 199 | $this->temporaryStorageFactory = $tempStorageFactory; | |||||
| 200 | $this->searchRequestName = $searchRequestName; | 227 | $this->searchRequestName = $searchRequestName; | |||
| 201 | $this->request = $request; | 228 | $this->search = $search ?: ObjectManager::getInstance()->get(\Magento\Search\Api\SearchInterface::class); | |||
| 202 | $this->searchResultFactory = $searchResultFactory ?? ObjectManager::getInstance() | 229 | $this->searchCriteriaBuilder = $searchCriteriaBuilder ?: ObjectManager::getInstance() | |||
| 203 | ->get(SearchResultFactory::class); | 230 | ->get(\Mageplaza\LayeredNavigation\Model\Search\SearchCriteriaBuilder::class); | |||
| 204 | $this->totalRecordsResolverFactory = $totalRecordsResolver; | 231 | $this->filterBuilder = $filterBuilder ?: ObjectManager::getInstance() | |||
| 232 | ->get(\Magento\Framework\Api\FilterBuilder::class); | |||||
| 233 | $this->searchCriteriaResolverFactory = $searchCriteriaResolverFactory ?: ObjectManager::getInstance() | |||||
| 234 | ->get(SearchCriteriaResolverFactory::class); | |||||
| 235 | $this->searchResultApplierFactory = $searchResultApplierFactory ?: ObjectManager::getInstance() | |||||
| 236 | ->get(SearchResultApplierFactory::class); | |||||
| 237 | $this->totalRecordsResolverFactory = $totalRecordsResolverFactory ?: ObjectManager::getInstance() | |||||
| 238 | ->get(TotalRecordsResolverFactory::class); | |||||
| 239 | $this->defaultFilterStrategyApplyChecker = $defaultFilterStrategyApplyChecker ?: ObjectManager::getInstance() | |||||
| 240 | ->get(DefaultFilterStrategyApplyChecker::class); | |||||
| 205 | } | 241 | } | |||
| 206 | 242 | |||||
| 207 | /** | 243 | /** | |||
| 208 | * MP LayerNavigation Clone collection | 244 | * MP function Clone collection | |||
| 209 | * | 245 | * | |||
| 210 | * @return | 246 | * @param bool $isReturn | |||
| 247 | * @return $this|Collection | |||||
| 211 | */ | 248 | */ | |||
| 212 | public function getCollectionClone( | 249 | public function getCollectionClone($isReturn = true) | |||
| 213 | { | 250 | { | |||
| 214 | if ($this->collectionClone === null) { | 251 | if ($this->collectionClone === null) { | |||
| 215 | $this->collectionClone = clone $this; | 252 | $this->collectionClone = clone $this; | |||
| 216 | $this->collectionClone->setSearchCriteriaBuilder($this->searchCriteriaBuilder->cloneObject()); | 253 | $this->collectionClone->setSearchCriteriaBuilder($this->searchCriteriaBuilder->cloneObject()); | |||
| 217 | } | 254 | } | |||
| 218 | 255 | |||||
| 256 | if ($isReturn) { | |||||
| 219 | $searchCriterialBuilder = $this->collectionClone->getSearchCriteriaBuilder()->cloneObject(); | 257 | $searchCriterialBuilder = $this->collectionClone->getSearchCriteriaBuilder()->cloneObject(); | |||
| 220 | 258 | |||||
| 221 | /** @var Collection $collectionClone */ | 259 | /** @var Collection $collectionClone */ | |||
| 222 | $collectionClone = clone $this->collectionClone; | 260 | $collectionClone = clone $this->collectionClone; | |||
| 223 | $collectionClone->setSearchCriteriaBuilder($searchCriterialBuilder); | 261 | $collectionClone->setSearchCriteriaBuilder($searchCriterialBuilder); | |||
| 224 | 262 | |||||
| 225 | return $collectionClone; | 263 | return $collectionClone; | |||
| 226 | } | 264 | } | |||
| 227 | 265 | |||||
| 228 | /** | |||||
| 229 | * MP LayerNavigation Add multi-filter categories | |||||
| 230 | * | |||||
| 231 | * @param $categories | |||||
| 232 | * | |||||
| 233 | * @return $this | |||||
| 234 | */ | |||||
| 235 | public function addLayerCategoryFilter($categories) | |||||
| 236 | { | |||||
| 237 | if ((strpos($this->getSearchEngine(), 'elasticsearch') !== false) | |||||
| 238 | || $this->getSearchEngine() === 'amasty_elastic' | |||||
| 239 | ) { | |||||
| 240 | $this->addFieldToFilter('category_ids', ['in' => $categories]); | |||||
| 241 | } else { | |||||
| 242 | $this->addFieldToFilter('category_ids', implode(',', $categories)); | |||||
| 243 | } | |||||
| 244 | ||||||
| 245 | return $this; | 266 | return $this; | |||
| 246 | } | 267 | } | |||
| 247 | 268 | |||||
| 248 | /** | 269 | /** | |||
| 249 | * MP LayerNavigation remove filter to load option item data | 270 | * MP function remove attribute from collection to count product in option attribute | |||
| 250 | * | 271 | * | |||
| 251 | * @param $attributeCode | 272 | * @param $attributeCode | |||
| 252 | * | 273 | * @return Collection | |||
| 253 | * @return $this | |||||
| 254 | */ | 274 | */ | |||
| 255 | public function removeAttributeSearch($attributeCode) | 275 | public function removeAttributeSearch($attributeCode) | |||
| 256 | { | 276 | { | |||
| 257 | if (is_array($attributeCode)) { | 277 | if (is_array($attributeCode)) { | |||
| 258 | foreach ($attributeCode as $attCode) { | 278 | foreach ($attributeCode as $attCode) { | |||
| 259 | $this->searchCriteriaBuilder->removeFilter($attCode); | 279 | $this->searchCriteriaBuilder->removeFilter($attCode); | |||
| 260 | } | 280 | } | |||
| 261 | } else { | 281 | } else { | |||
| 262 | $this->searchCriteriaBuilder->removeFilter($attributeCode); | 282 | $this->searchCriteriaBuilder->removeFilter($attributeCode); | |||
| 263 | } | 283 | } | |||
| 264 | 284 | |||||
| 265 | $this->_isFiltersRendered = false; | 285 | $this->_isFiltersRendered = false; | |||
| 266 | 286 | |||||
| 267 | return $this->loadWithFilter(); | 287 | return $this->loadWithFilter(); | |||
| 268 | } | 288 | } | |||
| 269 | 289 | |||||
| 270 | /** | 290 | /** | |||
| 271 | * @param $categoryIds | 291 | * MP function Add multi-filter categories | |||
| 292 | * | |||||
| 293 | * @param $categories | |||||
| 294 | * | |||||
| 295 | * @return $this | |||||
| 296 | */ | |||||
| 297 | public function addLayerCategoryFilter($categories) | |||||
| 298 | { | |||||
| 299 | $this->addFieldToFilter('category_ids', ['in' => $categories]); | |||||
| 300 | ||||||
| 301 | return $this; | |||||
| 302 | } | |||||
| 303 | ||||||
| 304 | /** | |||||
| 305 | * MP function reset category filter | |||||
| 272 | * | 306 | * | |||
| 307 | * @param $categoryIds | |||||
| 273 | * @return $this | 308 | * @return $this | |||
| 274 | */ | 309 | */ | |||
| 275 | public function resetCategoryFilter($categoryIds) | 310 | public function resetCategoryFilter($categoryIds) | |||
| 276 | { | 311 | { | |||
| 277 | $this->searchCriteriaBuilder->setCategoryFilter($categoryIds); | 312 | $this->searchCriteriaBuilder->setCategoryFilter($categoryIds); | |||
| 278 | 313 | |||||
| 279 | return $this; | 314 | return $this; | |||
| 280 | } | 315 | } | |||
| 281 | 316 | |||||
| 282 | /** | 317 | /** | |||
| 283 | * @param $categoryIds | 318 | * MP function set category filter | |||
| 284 | * | 319 | * | |||
| 320 | * @param $categoryIds | |||||
| 285 | * @return Collection | 321 | * @return Collection | |||
| 286 | */ | 322 | */ | |||
| 287 | public function setCategoryFilter($categoryIds) | 323 | public function setCategoryFilter($categoryIds) | |||
| 288 | { | 324 | { | |||
| 289 | $this->searchCriteriaBuilder->setCategoryFilter($categoryIds); | 325 | $this->searchCriteriaBuilder->setCategoryFilter($categoryIds); | |||
| 290 | $this->_isFiltersRendered = false; | 326 | $this->_isFiltersRendered = false; | |||
| 291 | 327 | |||||
| 292 | return $this->loadWithFilter(); | 328 | return $this->loadWithFilter(); | |||
| 293 | } | 329 | } | |||
| 294 | 330 | |||||
| 295 | /** | 331 | /** | |||
| 296 | * MP LayerNavigation Get attribute condition sql | 332 | * MP function reset category ids | |||
| 297 | * | |||||
| 298 | * @param $attribute | |||||
| 299 | * @param $condition | |||||
| 300 | * @param string $joinType | |||||
| 301 | * | 333 | * | |||
| 302 | * @return string | 334 | * @param string $categoryIds | |||
| 335 | * @return $this | |||||
| 303 | */ | 336 | */ | |||
| 304 | public function getAttributeConditionSql($attribute, $condition, $joinType = 'inner') | 337 | public function resetCategoryIds($categoryIds) | |||
| 305 | { | 338 | { | |||
| 306 | return $this->_getAttributeConditionSql($attribute, $condition, $joinType); | 339 | $this->_productLimitationFilters['category_id'] = $categoryIds; | |||
| 340 | if ($this->getStoreId() == Store::DEFAULT_STORE_ID) { | |||||
| 341 | $this->_applyZeroStoreProductLimitations(); | |||||
| 342 | } else { | |||||
| 343 | $this->_applyProductLimitations(); | |||||
| 344 | } | |||||
| 345 | ||||||
| 346 | return $this; | |||||
| 307 | } | 347 | } | |||
| 308 | 348 | |||||
| 309 | /** | 349 | /** | |||
| 310 | * MP LayerNavigation Reset Total records | 350 | * MP function Reset Total records | |||
| 311 | * | 351 | * | |||
| 312 | * @return $this | 352 | * @return $this | |||
| 313 | */ | 353 | */ | |||
| 314 | public function resetTotalRecords() | 354 | public function resetTotalRecords() | |||
| 315 | { | 355 | { | |||
| 316 | $this->_totalRecords = null; | 356 | $this->_totalRecords = null; | |||
| 317 | 357 | |||||
| 318 | return $this; | 358 | return $this; | |||
| 319 | } | 359 | } | |||
| 320 | 360 | |||||
| 321 | /** | 361 | /** | |||
| 322 | * @return SearchInterface | 362 | * Get search. | |||
| 323 | * @deprecated | 363 | * | |||
| 364 | * @deprecated 100.1.0 | |||||
| 365 | * @return \Magento\Search\Api\SearchInterface | |||||
| 324 | */ | 366 | */ | |||
| 325 | private function getSearch() | 367 | private function getSearch() | |||
| 326 | { | 368 | { | |||
| 327 | if ($this->search === null) { | 369 | if ($this->search === null) { | |||
| 328 | $this->search = ObjectManager::getInstance()->get( | 370 | $this->search = ObjectManager::getInstance()->get(\Magento\Search\Api\SearchInterface::class); | |||
| 329 | } | 371 | } | |||
| 330 | ||||||
| 331 | return $this->search; | 372 | return $this->search; | |||
| 332 | } | 373 | } | |||
| 333 | 374 | |||||
| 334 | /** | 375 | /** | |||
| 335 | * @param SearchInterface $object | 376 | * Test search. | |||
| 336 | * | 377 | * | |||
| 378 | * @deprecated 100.1.0 | |||||
| 379 | * @param \Magento\Search\Api\SearchInterface $object | |||||
| 337 | * @return void | 380 | * @return void | |||
| 338 | * @deprecated | 381 | * @since 100.1.0 | |||
| 339 | * | |||||
| 340 | */ | 382 | */ | |||
| 341 | public function setSearch( | 383 | public function setSearch(\Magento\Search\Api\SearchInterface $object) | |||
| 342 | { | 384 | { | |||
| 343 | $this->search = $object; | 385 | $this->search = $object; | |||
| 344 | } | 386 | } | |||
| 345 | 387 | |||||
| 346 | /** | 388 | /** | |||
| 347 | * @return SearchCriteriaBuilder | 389 | * Set search criteria builder. | |||
| 348 | * @deprecated | 390 | * | |||
| 391 | * @deprecated 100.1.0 | |||||
| 392 | * @return \Mageplaza\LayeredNavigation\Model\Search\SearchCriteriaBuilder | |||||
| 349 | */ | 393 | */ | |||
| 350 | public function getSearchCriteriaBuilder() | 394 | private function getSearchCriteriaBuilder() | |||
| 351 | { | 395 | { | |||
| 352 | if ($this->searchCriteriaBuilder === null) { | 396 | if ($this->searchCriteriaBuilder === null) { | |||
| 353 | $this->searchCriteriaBuilder = ObjectManager::getInstance() | 397 | $this->searchCriteriaBuilder = ObjectManager::getInstance() | |||
| 354 | ->get( | 398 | ->get(\Mageplaza\LayeredNavigation\Model\Search\SearchCriteriaBuilder::class); | |||
| 355 | } | 399 | } | |||
| 356 | ||||||
| 357 | return $this->searchCriteriaBuilder; | 400 | return $this->searchCriteriaBuilder; | |||
| 358 | } | 401 | } | |||
| 359 | 402 | |||||
| 360 | /** | 403 | /** | |||
| 361 | * @param | 404 | * Set search criteria builder. | |||
| 405 | * | |||||
| 406 | * @deprecated 100.1.0 | |||||
| 407 | * @param \Mageplaza\LayeredNavigation\Model\Search\SearchCriteriaBuilder $object | |||||
| 408 | * @return void | |||||
| 409 | * @since 100.1.0 | |||||
| 362 | */ | 410 | */ | |||
| 363 | public function setSearchCriteriaBuilder( | 411 | public function setSearchCriteriaBuilder(\Mageplaza\LayeredNavigation\Model\Search\SearchCriteriaBuilder $object) | |||
| 364 | { | 412 | { | |||
| 365 | $this->searchCriteriaBuilder = $object; | 413 | $this->searchCriteriaBuilder = $object; | |||
| 366 | } | 414 | } | |||
| 367 | 415 | |||||
| 368 | /** | 416 | /** | |||
| 369 | * @return FilterBuilder | 417 | * Get filter builder. | |||
| 370 | * @deprecated | 418 | * | |||
| 419 | * @deprecated 100.1.0 | |||||
| 420 | * @return \Magento\Framework\Api\FilterBuilder | |||||
| 371 | */ | 421 | */ | |||
| 372 | private function getFilterBuilder() | 422 | private function getFilterBuilder() | |||
| 373 | { | 423 | { | |||
| 374 | if ($this->filterBuilder === null) { | 424 | if ($this->filterBuilder === null) { | |||
| 375 | $this->filterBuilder = ObjectManager::getInstance()->get( | 425 | $this->filterBuilder = ObjectManager::getInstance()->get(\Magento\Framework\Api\FilterBuilder::class); | |||
| 376 | } | 426 | } | |||
| 377 | ||||||
| 378 | return $this->filterBuilder; | 427 | return $this->filterBuilder; | |||
| 379 | } | 428 | } | |||
| 380 | 429 | |||||
| 381 | /** | 430 | /** | |||
| 382 | * @param FilterBuilder $object | 431 | * Set filter builder. | |||
| 383 | * | 432 | * | |||
| 433 | * @deprecated 100.1.0 | |||||
| 434 | * @param \Magento\Framework\Api\FilterBuilder $object | |||||
| 384 | * @return void | 435 | * @return void | |||
| 385 | * @deprecated | 436 | * @since 100.1.0 | |||
| 386 | * | |||||
| 387 | */ | 437 | */ | |||
| 388 | public function setFilterBuilder( | 438 | public function setFilterBuilder(\Magento\Framework\Api\FilterBuilder $object) | |||
| 389 | { | 439 | { | |||
| 390 | $this->filterBuilder = $object; | 440 | $this->filterBuilder = $object; | |||
| 391 | } | 441 | } | |||
| 392 | 442 | |||||
| 393 | /** | 443 | /** | |||
| 394 | * Apply attribute filter to facet collection | 444 | * Apply attribute filter to facet collection | |||
| 395 | * | 445 | * | |||
| 396 | * @param string $field | 446 | * @param string $field | |||
| 397 | * @param | 447 | * @param mixed|null $condition | |||
| 398 | * | |||||
| 399 | * @return $this | 448 | * @return $this | |||
| 400 | */ | 449 | */ | |||
| 401 | public function addFieldToFilter($field, $condition = null) | 450 | public function addFieldToFilter($field, $condition = null) | |||
| 402 | { | 451 | { | |||
| 403 | ||||||
| 404 | if ($this->searchResult !== null && $this->request->getFullActionName() !== 'mpproductfinder_finder_find') { | 452 | if ($this->searchResult !== null && $this->request->getFullActionName() !== 'mpproductfinder_finder_find') { | |||
| 405 | throw new | 453 | throw new \RuntimeException('Illegal state'); | |||
| 406 | } | 454 | } | |||
| 407 | 455 | |||||
| 408 | $this->getSearchCriteriaBuilder(); | 456 | $this->getSearchCriteriaBuilder(); | |||
| 409 | $this->getFilterBuilder(); | 457 | $this->getFilterBuilder(); | |||
| 410 | 458 | |||||
| 411 | if (isset($condition['in']) | 459 | if (isset($condition['in'])) { | |||
| 412 | && (strpos($this->getSearchEngine(), 'elasticsearch') !== false | |||||
| 413 | || $this->getSearchEngine() === 'amasty_elastic') | |||||
| 414 | ) { | |||||
| 415 | $this->filterBuilder->setField($field); | 460 | $this->filterBuilder->setField($field); | |||
| 416 | $this->filterBuilder->setValue($condition['in']); | 461 | $this->filterBuilder->setValue($condition['in']); | |||
| 417 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | 462 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||
| 418 | } elseif (!is_array($condition) || !in_array(key($condition), ['from', 'to'] | 463 | } elseif (!is_array($condition) || !in_array(key($condition), ['from', 'to'], true)) { | |||
| 419 | $this->filterBuilder->setField($field); | 464 | $this->filterBuilder->setField($field); | |||
| 420 | $this->filterBuilder->setValue($condition); | 465 | $this->filterBuilder->setValue($condition); | |||
| 421 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | 466 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||
| 422 | } else { | 467 | } else { | |||
| 423 | if (!empty($condition['from'])) { | 468 | if (!empty($condition['from'])) { | |||
| 424 | $this->filterBuilder->setField("{$field}.from"); | 469 | $this->filterBuilder->setField("{$field}.from"); | |||
| 425 | $this->filterBuilder->setValue($condition['from']); | 470 | $this->filterBuilder->setValue($condition['from']); | |||
| 426 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | 471 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||
| 427 | } | 472 | } | |||
| 428 | if (!empty($condition['to'])) { | 473 | if (!empty($condition['to'])) { | |||
| 429 | $this->filterBuilder->setField("{$field}.to"); | 474 | $this->filterBuilder->setField("{$field}.to"); | |||
| 430 | $this->filterBuilder->setValue($condition['to']); | 475 | $this->filterBuilder->setValue($condition['to']); | |||
| 431 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | 476 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||
| 432 | } | 477 | } | |||
| 433 | } | 478 | } | |||
| 434 | return $this; | 479 | return $this; | |||
| 435 | } | 480 | } | |||
| 436 | 481 | |||||
| 437 | /** | 482 | /** | |||
| 483 | * @inheritDoc | |||||
| 484 | * @since 101.0.4 | |||||
| 485 | */ | |||||
| 486 | public function clear() | |||||
| 487 | { | |||||
| 488 | $this->searchResult = null; | |||||
| 489 | $this->setFlag('has_category_filter', false); | |||||
| 490 | ||||||
| 491 | return parent::clear(); | |||||
| 492 | } | |||||
| 493 | ||||||
| 494 | /** | |||||
| 495 | * @inheritDoc | |||||
| 496 | * @since 101.0.4 | |||||
| 497 | */ | |||||
| 498 | protected function _reset() | |||||
| 499 | { | |||||
| 500 | $this->searchResult = null; | |||||
| 501 | $this->setFlag('has_category_filter', false); | |||||
| 502 | ||||||
| 503 | return parent::_reset(); | |||||
| 504 | } | |||||
| 505 | ||||||
| 506 | /** | |||||
| 507 | * @inheritdoc | |||||
| 508 | * @since 101.0.4 | |||||
| 509 | */ | |||||
| 510 | public function _loadEntities($printQuery = false, $logQuery = false) | |||||
| 511 | { | |||||
| 512 | $this->getEntity(); | |||||
| 513 | ||||||
| 514 | $this->printLogQuery($printQuery, $logQuery); | |||||
| 515 | ||||||
| 516 | try { | |||||
| 517 | /** | |||||
| 518 | * Prepare select query | |||||
| 519 | * @var string $query | |||||
| 520 | */ | |||||
| 521 | $query = $this->getSelect(); | |||||
| 522 | $rows = $this->_fetchAll($query); | |||||
| 523 | } catch (\Exception $e) { | |||||
| 524 | $this->printLogQuery(false, true, $query); | |||||
| 525 | throw $e; | |||||
| 526 | } | |||||
| 527 | ||||||
| 528 | $position = 0; | |||||
| 529 | foreach ($rows as $value) { | |||||
| 530 | if ($this->getFlag('has_category_filter')) { | |||||
| 531 | $value['cat_index_position'] = $position++; | |||||
| 532 | } | |||||
| 533 | $object = $this->getNewEmptyItem()->setData($value); | |||||
| 534 | $this->addItem($object); | |||||
| 535 | if (isset($this->_itemsById[$object->getId()])) { | |||||
| 536 | $this->_itemsById[$object->getId()][] = $object; | |||||
| 537 | } else { | |||||
| 538 | $this->_itemsById[$object->getId()] = [$object]; | |||||
| 539 | } | |||||
| 540 | } | |||||
| 541 | if ($this->getFlag('has_category_filter')) { | |||||
| 542 | $this->setFlag('has_category_filter', false); | |||||
| 543 | } | |||||
| 544 | ||||||
| 545 | return $this; | |||||
| 546 | } | |||||
| 547 | ||||||
| 548 | /** | |||||
| 438 | * Add search query filter | 549 | * Add search query filter | |||
| 439 | * | 550 | * | |||
| 440 | * @param string $query | 551 | * @param string $query | |||
| 441 | * | |||||
| 442 | * @return $this | 552 | * @return $this | |||
| 443 | */ | 553 | */ | |||
| 444 | public function addSearchFilter($query) | 554 | public function addSearchFilter($query) | |||
| 445 | { | 555 | { | |||
| 446 | $this->queryText = trim($this->queryText . ' ' . $query); | 556 | $this->queryText = trim($this->queryText . ' ' . $query); | |||
| 447 | ||||||
| 448 | return $this; | 557 | return $this; | |||
| 449 | } | 558 | } | |||
| 450 | 559 | |||||
| 451 | /** | 560 | /** | |||
| 452 | * @inheritdoc | 561 | * @inheritdoc | |||
| 453 | */ | 562 | */ | |||
| 454 | public function setOrder($attribute, $dir = Select::SQL_DESC) | 563 | public function setOrder($attribute, $dir = Select::SQL_DESC) | |||
| 455 | { | 564 | { | |||
| 456 | $this->setSearchOrder($attribute, $dir); | 565 | $this->setSearchOrder($attribute, $dir); | |||
| 457 | if ($attribute === 'relevance') { | 566 | if ($this->defaultFilterStrategyApplyChecker->isApplicable()) { | |||
| 458 | $this->order[$attribute] = $dir; | |||||
| 459 | } else { | |||||
| 460 | parent::setOrder($attribute, $dir); | 567 | parent::setOrder($attribute, $dir); | |||
| 461 | } | 568 | } | |||
| 462 | 569 | |||||
| 463 | return $this; | 570 | return $this; | |||
| 464 | } | 571 | } | |||
| 465 | 572 | |||||
| 466 | /** | 573 | /** | |||
| 467 | * Add attribute to sort order. | 574 | * Add attribute to sort order. | |||
| 468 | * | 575 | * | |||
| 469 | * @param string $attribute | 576 | * @param string $attribute | |||
| 470 | * @param string $dir | 577 | * @param string $dir | |||
| 471 | * | |||||
| 472 | * @return $this | 578 | * @return $this | |||
| 473 | * @since 101.0.2 | 579 | * @since 101.0.2 | |||
| 474 | */ | 580 | */ | |||
| 475 | public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC) | 581 | public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC) | |||
| 476 | { | 582 | { | |||
| 477 | if ($attribute === 'relevance') { | 583 | if ($this->defaultFilterStrategyApplyChecker->isApplicable()) { | |||
| 478 | $this->setOrder($attribute, $dir); | |||||
| 479 | } else { | |||||
| 480 | parent::addAttributeToSort($attribute, $dir); | 584 | parent::addAttributeToSort($attribute, $dir); | |||
| 585 | } else { | |||||
| 586 | $this->setOrder($attribute, $dir); | |||||
| 481 | } | 587 | } | |||
| 482 | 588 | |||||
| 483 | return $this; | 589 | return $this; | |||
| 484 | } | 590 | } | |||
| 485 | 591 | |||||
| 486 | /** | 592 | /** | |||
| 487 | * Set sort order for search query. | 593 | * @inheritdoc | |||
| 488 | * | |||||
| 489 | * @param string $field | |||||
| 490 | * @param string $direction | |||||
| 491 | * | |||||
| 492 | * @return void | |||||
| 493 | */ | 594 | */ | |||
| 494 | private function setSearchOrder($field, $direction) | 595 | protected function _renderFiltersBefore() | |||
| 495 | { | 596 | { | |||
| 496 | $field = (string) $this->_getMappedField($field); | 597 | if ($this->isLoaded()) { | |||
| 497 | $direction = strtoupper($direction) == self::SORT_ORDER_ASC ? self::SORT_ORDER_ASC : self::SORT_ORDER_DESC; | 598 | return; | |||
| 498 | ||||||
| 499 | $this->searchOrders[$field] = $direction; | |||||
| 500 | } | 599 | } | |||
| 501 | 600 | |||||
| 502 | /** | 601 | $this->getCollectionClone(false); | |||
| 503 | * @throws LocalizedException | |||||
| 504 | * @throws Zend_Db_Exception | |||||
| 505 | */ | |||||
| 506 | protected function _renderFiltersBefore() | |||||
| 507 | { | |||||
| 508 | $this->getCollectionClone( | |||||
| 509 | $this->getSearchCriteriaBuilder(); | |||||
| 510 | $this->getFilterBuilder(); | |||||
| 511 | $this->getSearch(); | |||||
| 512 | 602 | |||||
| 513 | if ($this->searchRequestName !== 'quick_search_container' | 603 | if ($this->searchRequestName !== 'quick_search_container' | |||
| 514 | || trim($this->queryText) !== '' | 604 | || trim($this->queryText) !== '' | |||
| 515 | ) { | 605 | ) { | |||
| 516 | if ($this->queryText) { | 606 | $this->prepareSearchTermFilter(); | |||
| 517 | $this->filterBuilder->setField('search_term'); | 607 | $this->preparePriceAggregation(); | |||
| 518 | $this->filterBuilder->setValue($this->queryText); | |||||
| 519 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||||
| 520 | } | |||||
| 521 | ||||||
| 522 | $priceRangeCalculation = $this->_scopeConfig->getValue( | |||||
| 523 | AlgorithmFactory::XML_PATH_RANGE_CALCULATION, | |||||
| 524 | ScopeInterface::SCOPE_STORE | |||||
| 525 | ); | |||||
| 526 | if ($priceRangeCalculation) { | |||||
| 527 | $this->filterBuilder->setField('price_dynamic_algorithm'); | |||||
| 528 | $this->filterBuilder->setValue('auto'); | |||||
| 529 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||||
| 530 | } | |||||
| 531 | if ($this->request->getFullActionName() === 'catalogsearch_result_index') { | |||||
| 532 | $this->searchRequestName = 'quick_search_container'; | |||||
| 533 | $this->filterBuilder->setField('visibility'); | |||||
| 534 | $this->filterBuilder->setValue([3, 4]); | |||||
| 535 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||||
| 536 | } | |||||
| 537 | ||||||
| 538 | $searchCriteria = $this->searchCriteriaBuilder->create(); | |||||
| 539 | $searchCriteria->setRequestName($this->searchRequestName); | |||||
| 540 | $searchCriteria->setSortOrders($this->searchOrders); | |||||
| 541 | $searchCriteria->setCurrentPage((int) $this->_curPage); | |||||
| 542 | 608 | |||||
| 609 | $searchCriteria = $this->getSearchCriteriaResolver()->resolve(); | |||||
| 543 | try { | 610 | try { | |||
| 544 | $this->searchResult = $this->getSearch()->search($searchCriteria); | 611 | $this->searchResult = $this->getSearch()->search($searchCriteria); | |||
| 612 | $this->_totalRecords = $this->getTotalRecordsResolver($this->searchResult)->resolve(); | |||||
| 545 | } catch (EmptyRequestDataException $e) { | 613 | } catch (EmptyRequestDataException $e) { | |||
| 546 | $this->searchResult = $this->createEmptyResult(); | 614 | $this->searchResult = $this->createEmptyResult(); | |||
| 547 | } catch (Exception $e) { | 615 | } catch (NonExistingRequestNameException $e) { | |||
| 548 | throw new LocalizedException(__('Sorry, something went wrong. You can find out more in the error log.')); | 616 | $this->_logger->error($e->getMessage()); | |||
| 617 | throw new LocalizedException(__('An error occurred. For details, see the error log.')); | |||||
| 549 | } | 618 | } | |||
| 550 | } else { | 619 | } else { | |||
| 551 | $this->searchResult = $this->createEmptyResult(); | 620 | $this->searchResult = $this->createEmptyResult(); | |||
| 552 | } | 621 | } | |||
| 553 | 622 | |||||
| 554 | if (strpos($this->getSearchEngine(), 'elasticsearch') !== false) { | 623 | $this->getSearchResultApplier($this->searchResult)->apply(); | |||
| 555 | $this->ElasticSearchApply(); | |||||
| 556 | } else { | |||||
| 557 | $this->CatalogSearchApply(); | |||||
| 558 | } | |||||
| 559 | ||||||
| 560 | parent::_renderFiltersBefore(); | 624 | parent::_renderFiltersBefore(); | |||
| 561 | } | 625 | } | |||
| 562 | 626 | |||||
| 563 | /** | 627 | /** | |||
| 564 | * @return \Magento\Catalog\Model\ResourceModel\Product\Collection | 628 | * Create empty search result | |||
| 629 | * | |||||
| 630 | * @return SearchResultInterface | |||||
| 565 | */ | 631 | */ | |||
| 566 | protected function _renderFilters() | 632 | private function createEmptyResult() | |||
| 567 | { | 633 | { | |||
| 568 | $this->_filters = []; | 634 | return $this->searchResultFactory->create()->setItems([]); | |||
| 569 | ||||||
| 570 | return parent::_renderFilters(); | |||||
| 571 | } | 635 | } | |||
| 572 | 636 | |||||
| 573 | /** | 637 | /** | |||
| 574 | * sort product before load | 638 | * Set sort order for search query. | |||
| 639 | * | |||||
| 640 | * @param string $field | |||||
| 641 | * @param string $direction | |||||
| 642 | * @return void | |||||
| 575 | */ | 643 | */ | |||
| 576 | protected function _beforeLoad() | 644 | private function setSearchOrder($field, $direction) | |||
| 577 | { | 645 | { | |||
| 578 | $this->setOrder('entity_id'); | 646 | $field = (string)$this->_getMappedField($field); | |||
| 647 | $direction = strtoupper($direction) == self::SORT_ORDER_ASC ? self::SORT_ORDER_ASC : self::SORT_ORDER_DESC; | |||||
| 579 | 648 | |||||
| 580 | return parent::_beforeLoad(); | 649 | $this->searchOrders[$field] = $direction; | |||
| 581 | } | 650 | } | |||
| 582 | 651 | |||||
| 583 | /** | 652 | /** | |||
| 584 | * Create empty search result | 653 | * Get total records resolver. | |||
| 585 | * | 654 | * | |||
| 586 | * @return SearchResultInterface | 655 | * @param SearchResultInterface $searchResult | |||
| 656 | * @return TotalRecordsResolverInterface | |||||
| 587 | */ | 657 | */ | |||
| 588 | private function createEmptyResult() | 658 | private function getTotalRecordsResolver(SearchResultInterface $searchResult): TotalRecordsResolverInterface | |||
| 589 | { | 659 | { | |||
| 590 | return $this->searchResultFactory->create()->setItems([]); | 660 | return $this->totalRecordsResolverFactory->create( | |||
| 661 | [ | |||||
| 662 | 'searchResult' => $searchResult, | |||||
| 663 | ] | |||||
| 664 | ); | |||||
| 591 | } | 665 | } | |||
| 592 | 666 | |||||
| 593 | /** | 667 | /** | |||
| 594 | * Stub method for compatibility with other search engines | 668 | * Function to change the _getAllData variable | |||
| 595 | * | 669 | * | |||
| 670 | * @param $isGetAll | |||||
| 596 | * @return $this | 671 | * @return $this | |||
| 597 | */ | 672 | */ | |||
| 598 | public function setGeneralDefaultQuery() | 673 | public function setGetAllData($isGetAll){ | |||
| 599 | { | 674 | $this->_getAllData = $isGetAll; | |||
| 675 | ||||||
| 600 | return $this; | 676 | return $this; | |||
| 601 | } | 677 | } | |||
| 602 | 678 | |||||
| 603 | protected function CatalogSearchApply() | 679 | /** | |||
| 680 | * Get search criteria resolver. | |||||
| 681 | * | |||||
| 682 | * @return SearchCriteriaResolverInterface | |||||
| 683 | */ | |||||
| 684 | private function getSearchCriteriaResolver(): SearchCriteriaResolverInterface | |||||
| 604 | { | 685 | { | |||
| 605 | $temporaryStorage = $this->temporaryStorageFactory->create(); | 686 | $size = $this->_getAllData ? 1000 : $this->getPageSize(); | |||
| 606 | $table = $temporaryStorage->storeDocuments($this->searchResult->getItems()); | 687 | $currentPage = $this->_getAllData ? 1 : (int)$this->_curPage; | |||
| 607 | 688 | |||||
| 608 | $this->getSelect()->joinInner( | 689 | return $this->searchCriteriaResolverFactory->create( | |||
| 609 | [ | 690 | [ | |||
| 610 | 'search_result' => $table->getName(), | 691 | 'builder' => $this->getSearchCriteriaBuilder(), | |||
| 611 | ], | 692 | 'collection' => $this, | |||
| 612 | 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, | 693 | 'searchRequestName' => $this->searchRequestName, | |||
| 613 | [] | 694 | 'currentPage' => $currentPage, | |||
| 695 | 'size' => $size, | |||||
| 696 | 'orders' => $this->searchOrders, | |||||
| 697 | | |||||
| 614 | ); | 698 | ); | |||
| 615 | if ($this->order && isset($this->order['relevance'])) { | |||||
| 616 | $this->getSelect()->order( | |||||
| 617 | 'search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['relevance'] | |||||
| 618 | ); | |||||
| 619 | } | |||||
| 620 | } | 699 | } | |||
| 621 | 700 | |||||
| 622 | /** | 701 | /** | |||
| 623 | * @inheritdoc | 702 | * Get search result applier. | |||
| 703 | * | |||||
| 704 | * @param SearchResultInterface $searchResult | |||||
| 705 | * @return SearchResultApplierInterface | |||||
| 624 | */ | 706 | */ | |||
| 625 | protected function ElasticSearchApply() | 707 | private function getSearchResultApplier(SearchResultInterface $searchResult): SearchResultApplierInterface | |||
| 626 | { | 708 | { | |||
| 627 | if (empty($this->searchResult->getItems())) { | 709 | $size = $this->_getAllData ? 1000 : $this->getPageSize(); | |||
| 628 | $this->getSelect()->where('NULL'); | 710 | $currentPage = $this->_getAllData ? 1 : (int)$this->_curPage; | |||
| 629 | 711 | |||||
| 630 | return; | 712 | return $this->searchResultApplierFactory->create( | |||
| 713 | [ | |||||
| 714 | 'collection' => $this, | |||||
| 715 | 'searchResult' => $searchResult, | |||||
| 716 | /** This variable sets by serOrder method, but doesn't have a getter method. */ | |||||
| 717 | 'orders' => $this->_orders, | |||||
| 718 | 'size' => $size, | |||||
| 719 | 'currentPage' => $currentPage, | |||||
| 720 | ] | |||||
| 721 | ); | |||||
| 631 | } | 722 | } | |||
| 632 | 723 | |||||
| 633 | $ids = []; | 724 | /** | |||
| 634 | foreach ($this->searchResult->getItems() as $item) { | 725 | * @inheritdoc | |||
| 635 | $ids[] = (int) $item->getId(); | 726 | * @since 100.2.3 | |||
| 727 | */ | |||||
| 728 | protected function _beforeLoad() | |||||
| 729 | { | |||||
| 730 | /* | |||||
| 731 | * This order is required to force search results be the same | |||||
| 732 | * for the same requests and products with the same relevance | |||||
| 733 | * NOTE: this does not replace existing orders but ADDs one more | |||||
| 734 | */ | |||||
| 735 | $this->setOrder('entity_id'); | |||||
| 736 | return parent::_beforeLoad(); | |||||
| 636 | } | 737 | } | |||
| 637 | $this->getSelect() | 738 | ||||
| 638 | ->where('e.entity_id IN (?)', $ids); | 739 | /** | |||
| 639 | $sortOrder = $this->searchResult->getSearchCriteria() | 740 | * Render filters. | |||
| 640 | ->getSortOrders(); | 741 | * | |||
| 641 | if (!empty($sortOrder['price']) && $this->getLimitationFilters()->isUsingPriceIndex()) { | 742 | * @return $this | |||
| 642 | $sortDirection = $sortOrder['price']; | 743 | */ | |||
| 643 | $this->getSelect() | 744 | protected function _renderFilters() | |||
| 644 | ->order( | 745 | { | |||
| 645 | new \Zend_Db_Expr("price_index.price = 0, price_index.price {$sortDirection}") | 746 | $this->_filters = []; | |||
| 646 | ); | 747 | return parent::_renderFilters(); | |||
| 647 | } else { | |||||
| 648 | $orderList = implode(',', $ids); | |||||
| 649 | $this->getSelect() | |||||
| 650 | ->order(new \Zend_Db_Expr("FIELD(e.entity_id,$orderList)")); | |||||
| 651 | } | 748 | } | |||
| 749 | ||||||
| 750 | /** | |||||
| 751 | * Stub method for compatibility with other search engines | |||||
| 752 | * | |||||
| 753 | * @return $this | |||||
| 754 | */ | |||||
| 755 | public function setGeneralDefaultQuery() | |||||
| 756 | { | |||||
| 757 | return $this; | |||||
| 652 | } | 758 | } | |||
| 653 | 759 | |||||
| 654 | /** | 760 | /** | |||
| 655 | * Return field faceted data from faceted search result | 761 | * Return field faceted data from faceted search result | |||
| 656 | * | 762 | * | |||
| 657 | * @param string $field | 763 | * @param string $field | |||
| 658 | * | |||||
| 659 | * @return array | 764 | * @return array | |||
| 660 | * @throws StateException | 765 | * @throws StateException | |||
| 661 | */ | 766 | */ | |||
| 662 | public function getFacetedData($field) | 767 | public function getFacetedData($field) | |||
| 663 | { | 768 | { | |||
| 664 | $this->_renderFilters(); | 769 | $this->_renderFilters(); | |||
| 665 | $result = []; | 770 | $result = []; | |||
| 666 | ||||||
| 667 | $aggregations = $this->searchResult->getAggregations(); | 771 | $aggregations = $this->searchResult->getAggregations(); | |||
| 668 | // This behavior is for case with empty object when we got EmptyRequestDataException | 772 | // This behavior is for case with empty object when we got EmptyRequestDataException | |||
| 669 | if (null !== $aggregations) { | 773 | if (null !== $aggregations) { | |||
| 670 | $bucket = $aggregations->getBucket($field . RequestGenerator::BUCKET_SUFFIX); | 774 | $bucket = $aggregations->getBucket($field . RequestGenerator::BUCKET_SUFFIX); | |||
| 671 | if ($bucket) { | 775 | if ($bucket) { | |||
| 672 | foreach ($bucket->getValues() as $value) { | 776 | foreach ($bucket->getValues() as $value) { | |||
| 673 | $metrics = $value->getMetrics(); | 777 | $metrics = $value->getMetrics(); | |||
| 674 | $result[$metrics['value']] = $metrics; | 778 | $result[$metrics['value']] = $metrics; | |||
| 675 | } | 779 | } | |||
| 676 | } else { | 780 | } else { | |||
| 677 | throw new StateException(__('Bucket does not exist')); | 781 | throw new StateException(__("The bucket doesn't exist.")); | |||
| 678 | } | 782 | } | |||
| 679 | } | 783 | } | |||
| 680 | ||||||
| 681 | return $result; | 784 | return $result; | |||
| 682 | } | 785 | } | |||
| 683 | 786 | |||||
| 684 | /** | 787 | /** | |||
| 685 | * Specify category filter for product collection | 788 | * Specify category filter for product collection | |||
| 686 | * | 789 | * | |||
| 687 | * @param | 790 | * @param \Magento\Catalog\Model\Category $category | |||
| 688 | * | 791 | * @return $this | |||
| 689 | * @return \Magento\Catalog\Model\ResourceModel\Product\Collection | |||||
| 690 | */ | 792 | */ | |||
| 691 | public function addCategoryFilter( | 793 | public function addCategoryFilter(\Magento\Catalog\Model\Category $category) | |||
| 692 | { | 794 | { | |||
| 693 | $this->addFieldToFilter('category_ids', $category->getId()); | 795 | $this->addFieldToFilter('category_ids', $category->getId()); | |||
| 694 | ||||||
| 695 | return parent::addCategoryFilter($category); | |||||
| 696 | } | |||||
| 697 | ||||||
| 698 | /** | 796 | /** | |||
| 699 | * @param string $categoryIds | 797 | * This changes need in backward compatible reasons for support dynamic improved algorithm | |||
| 700 | * | 798 | * for price aggregation process. | |||
| 701 | * @return $this | |||||
| 702 | */ | 799 | */ | |||
| 703 | public function resetCategoryIds($categoryIds) | 800 | if ($this->defaultFilterStrategyApplyChecker->isApplicable()) { | |||
| 704 | { | 801 | parent::addCategoryFilter($category); | |||
| 705 | $this->_productLimitationFilters['category_id'] = $categoryIds; | |||||
| 706 | if ($this->getStoreId() == Store::DEFAULT_STORE_ID) { | |||||
| 707 | $this->_applyZeroStoreProductLimitations(); | |||||
| 708 | } else { | 802 | } else { | |||
| 709 | $this->_applyProductLimitations(); | 803 | $this->setFlag('has_category_filter', true); | |||
| 804 | $this->_productLimitationPrice(); | |||||
| 710 | } | 805 | } | |||
| 711 | 806 | |||||
| 712 | return $this; | 807 | return $this; | |||
| 713 | } | 808 | } | |||
| 714 | 809 | |||||
| 715 | /** | 810 | /** | |||
| 716 | * Set product visibility filter for enabled products | 811 | * Set product visibility filter for enabled products | |||
| 717 | * | 812 | * | |||
| 718 | * @param array $visibility | 813 | * @param array $visibility | |||
| 719 | * | 814 | * @return $this | |||
| 720 | * @return \Magento\Catalog\Model\ResourceModel\Product\Collection | |||||
| 721 | */ | 815 | */ | |||
| 722 | public function setVisibility($visibility) | 816 | public function setVisibility($visibility) | |||
| 723 | { | 817 | { | |||
| 724 | $this->addFieldToFilter('visibility', $visibility); | 818 | $this->addFieldToFilter('visibility', $visibility); | |||
| 819 | /** | |||||
| 820 | * This changes need in backward compatible reasons for support dynamic improved algorithm | |||||
| 821 | * for price aggregation process. | |||||
| 822 | */ | |||||
| 823 | if ($this->defaultFilterStrategyApplyChecker->isApplicable()) { | |||||
| 824 | parent::setVisibility($visibility); | |||||
| 825 | } | |||||
| 725 | 826 | |||||
| 726 | return parent::setVisibility($visibility); | 827 | return $this; | |||
| 727 | } | 828 | } | |||
| 728 | 829 | |||||
| 729 | /** | 830 | /** | |||
| 730 | * Get Search Engine Config | 831 | * Prepare search term filter for text query. | |||
| 731 | * | 832 | * | |||
| 732 | * @return string | 833 | * @return void | |||
| 733 | */ | 834 | */ | |||
| 734 | public function getSearchEngine() | 835 | private function prepareSearchTermFilter(): void | |||
| 735 | { | 836 | { | |||
| 736 | return $this->_scopeConfig->getValue(Custom::XML_PATH_CATALOG_SEARCH_ENGINE, ScopeInterface::SCOPE_STORE); | 837 | if ($this->queryText) { | |||
| 838 | $this->filterBuilder->setField('search_term'); | |||||
| 839 | $this->filterBuilder->setValue($this->queryText); | |||||
| 840 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||||
| 841 | } | |||||
| 737 | } | 842 | } | |||
| 738 | 843 | |||||
| 739 | /** | 844 | /** | |||
| 740 | * @throws LocalizedException | 845 | * Prepare price aggregation algorithm. | |||
| 741 | * @throws Zend_Db_Exception | 846 | * | |||
| 847 | * @return void | |||||
| 742 | */ | 848 | */ | |||
| 743 | public function getRenderFiltersBefore() | 849 | private function preparePriceAggregation(): void | |||
| 744 | { | 850 | { | |||
| 745 | $this->_renderFilters(); | 851 | $priceRangeCalculation = $this->_scopeConfig->getValue( | |||
| 746 | 852 | \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, | ||||
| 747 | $this->getSelect()->where('rt.rating_summary >= 0'); | 853 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE | |||
| 748 | 854 | ); | ||||
| 749 | return $this; | 855 | if ($priceRangeCalculation) { | |||
| 856 | $this->filterBuilder->setField('price_dynamic_algorithm'); | |||||
| 857 | $this->filterBuilder->setValue($priceRangeCalculation); | |||||
| 858 | $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create()); | |||||
| 859 | } | |||||
| 750 | } | 860 | } | |||
| 751 | } | 861 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.